package com.zm.shop.users.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zm.shop.common.utils.PageUtils;
import com.zm.shop.common.utils.Query;

import com.zm.shop.users.dao.UsersDao;
import com.zm.shop.users.entity.UsersEntity;
import com.zm.shop.users.service.UsersService;


@Service("usersService")
public class UsersServiceImpl extends ServiceImpl<UsersDao, UsersEntity> implements UsersService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<UsersEntity> page = this.page(new Query<UsersEntity>().getPage(params),new QueryWrapper<UsersEntity>());

        //1.分页
        IPage<UsersEntity> page=new Query<UsersEntity>().getPage(params);
        //2.查询条件
        QueryWrapper<UsersEntity> queryWrapper = new QueryWrapper<>();
        //获取数据
        Object key = params.get("key");
        if (key != null && !StringUtils.isEmpty(key.toString())){ //这里强转字符串类型会有一定程度的报错
            queryWrapper.like("username",key);
        }
        //3.组合查询
        IPage<UsersEntity> page1 = this.page(page,queryWrapper);

        return new PageUtils(page1);
    }


}